package main

import "fmt"

func sum(s []int, c chan int) {
	sum := 0
	for _, val := range s {
		sum += val
	}

	c <- sum
}

func main() {
	s := []int{1, 2, 3, 4, 5}

	c := make(chan int, 2)

	go sum(s, c)

	fmt.Println(s[:len(s)/2])

	go sum(s[:len(s)/2], c)

	x, y := <-c, <-c // 从通道c中接收

	fmt.Println(x, y, x+y)
}
